﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using CommonUtility;
using System.Web.Script.Serialization;
using Model;
namespace WebApplication
{
    public partial class RoleInf : BasePage
    {
        const string FUN_ID = "FA02";
        protected void Page_Load(object sender, EventArgs e)
        {
            string action = Common.ToString(Request["Action"]);
            switch (action)
            {
                case "GetList":
                    Response.Write(LoadList());
                    Response.End();
                    break;
                case "Save":
                    Response.Write(Save());
                    Response.End();
                    break;
                case "Process":
                    Response.Write(Process(Common.ToString(Request["flag"])));
                    Response.End();
                    break;

            }
            if (!IsPostBack && string.IsNullOrEmpty(action))
            {
                bllPermission Perm = new bllPermission(oUser.UserID, FUN_ID);
                hdPermission.Value = new JavaScriptSerializer().Serialize(Perm);
            }
        }

        /// <summary>
        /// 获取明细
        /// </summary>
        /// <returns></returns>
        private string LoadList()
        {
            string roleID = Common.ConvertSql(Common.ToString(Request["roleID"]));
            string roleDesc = Common.ConvertSql(Common.ToString(Request["roleDesc"]));

            string _sortOrder = Common.ConvertSql(Common.ToString(Request["sortname"]) + " " + Common.ToString(Request["sortorder"]));
            int _page = Common.ToInt32(Request["page"]);
            int _pagesize = Common.ToInt32(Request["pagesize"]);

            string result = string.Empty;
            result = new bllRole().GetAllRole(roleID, roleDesc, _sortOrder, _page, _pagesize, oUser);
            return result;
        }


        /// <summary>
        /// 保存数据
        /// </summary>
        /// <returns></returns>
        private string Save()
        {
            string result = string.Empty;
            string roleID = Common.ToString(Request["RoleID"]);
            string roleDesc = Common.ToString(Request["RoleDesc"]);
            string rid = Common.ToString(Request["RID"]);
            result = new bllRole().Save(FUN_ID, rid, roleID, roleDesc, oUser);
            return result;
            
        }

        /// <summary>
        /// 设置Flag
        /// </summary>
        /// <param name="flag">A or I</param>
        /// <returns></returns>
        private string Process(string flag)
        {
            string res = string.Empty;
            res = new bllRole().Process(FUN_ID, Common.ConvertSql(Common.ToString(Request["rids"])), flag, oUser);

            return res;
        }
    }
}